#pragma once
#include "../UIElement.h"
#include "../IUITextElement.h"

enum TextChangedEvent
{
	NoEvent,
	TextDeleted,
	TextAdded,
	CursorMovedRight,
	CursorMovedLeft
};

class UITextbox : public UIElement, public IUITextElement
{
public:
	UITextbox();
	UITextbox(float x, float y);
	UITextbox(float x, float y, float width, float height);
	UITextbox(float x, float y, float width, float height, std::string Text);
	UITextbox(float x, float y, float width, float height, std::string Text, std::string FontName);
	UITextbox(float x, float y, float width, float height, std::string Text, std::string FontName, int FontSize);
	UITextbox(float x, float y, float width, float height, std::string Text, std::string FontName, int FontSize, Color color);
	UITextbox(float x, float y, float width, float height, std::string Text, std::string FontName, int FontSize, Color color, bool roundedCornersEnabled);
	UITextbox(float x, float y, float width, float height, std::string Text, std::string FontName, int FontSize, Color color, bool roundedCornersEnabled, float roundedCornerRadiusX, float roundedCornerRadiusY);


	// Draws the element on the screen and has to be called between graphics.BeginDraw() and graphics.EndDraw()
	void __stdcall Draw(Graphics* graphics);

	float Stroke = 1.0f;
	float MarginsLeft = 6.2f;
	float MarginsTop = 0.6f;
	bool Filled = true;
	bool RoundedCorners = true;
	float RoundCornerRadiusX = 4, RoundCornerRadiusY = 4;
	bool Active = false;
	int CursorPosition = 0;

	void CursorPositionCorrection();
	void VisibleIndicesCorrection(TextChangedEvent evt);

	size_t _visible_start_index, _visible_end_index;

private:
	void SetDefaultOptions();
	void SetupEventListeners();

	size_t _Max_Char_Count = 0;
	float _Text_Width_In_Pixels = 0;
	float _Text_Height_In_Pixels = 0;

	std::string CalculateVisibleText();
};
